﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TribesPSO
{
    /// <summary>
    /// An immutable class that represents a solution to an IObjectiveFunction
    /// </summary>
    public sealed class Solution
    {
        private readonly double error;
        private readonly EuclidianVector position;

        /// <summary>
        /// Gets the numerical value of the solution
        /// </summary>
        public double Error { get { return error; } }

        /// <summary>
        /// Gets the EuclidianVector that represents the location of the solution
        /// </summary>
        public EuclidianVector Position { get { return position; } }

        /// <summary>
        /// Initializes a new solution object with the specified error and position
        /// </summary>
        /// <param name="position">The position where the solution was evaluated</param>
        /// <param name="error">The numerical value of the solution</param>
        public Solution(EuclidianVector position, double error)
        {
            this.position = position;
            this.error = error;
        }

        /// <summary>
        /// Initializes a new solution object by evaluating function at position and saving the
        /// numerical result
        /// </summary>
        /// <param name="position">The position where the solution is evaluated</param>
        /// <param name="function">The IObjectiveFunction to solve</param>
        public Solution(EuclidianVector position, IObjectiveFunction function)
        {
            if (function == null) throw new ArgumentNullException("function");
            this.position = position;
            this.error = function.Evaluate(position);
        }
    }
}
